#include<iostream>
#include<sys/select.h>
#include<cstdio>
#include<unistd.h>
#include "SetNonBlock.hpp"



int main()
{
	char buffer[1024];
	SetNonBlock(0);
	while(true)
	{
		int n = read(0,buffer,sizeof(buffer)-1);
		if(n>0)//正常读取
		{
			buffer[n]=0;
			std::cout<<"echo:"<<buffer<<std::endl;
		}
		else if(n==0)//用户退出了
		{
			std::cout<<"client quit! \n";
			break;
		}
		else//异常报错
		{
			if(errno == EWOULDBLOCK)
			{
				std::cout<<"缓冲区内没有数据\n";
				//这里可以做其他事情
				sleep(1);
				continue;
			}
			else if (errno ==EINTR)
			{
				std::cout<<"读取被中断了\n";
				continue;
			}
			else
			{
				//真正的意外错误
				perror("read");
				break;
			};
		};
	};
	return 0;


};
